﻿package cn.poco.pepsi.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.poco.pepsi.R;
import cn.poco.pepsi.bean.City;

public class AdapterSwitchCityList extends BaseAdapter {
	private Context context;
	private List<City> list;
	private LayoutInflater myInfater;

	public AdapterSwitchCityList(Context context, List<City> list) {
		this.context = context;
		this.list = list;
		myInfater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		if (list.get(list.size()-1).getKey().equals("111111")) {
			 return 6;
		}else {
			return list.size();
		}
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (position == 0) {
			String showText = list.get(position).getName();
			convertView = myInfater.inflate(R.layout.switch_city_head, null);
			ViewHolderHead viewHead = new ViewHolderHead();
			viewHead.title = (TextView) convertView.findViewById(R.id.gpscity);
			viewHead.title.setPadding(10, 0, 0, 0);
			viewHead.title.setText(showText);
		} else {
			convertView = myInfater.inflate(R.layout.switch_city_item, null);
			ViewHolderItem viewHolderItem = new ViewHolderItem();
			viewHolderItem.content = (TextView) convertView.findViewById(R.id.switchcity);
			viewHolderItem.content.setText(list.get(position).getName());
		}
		return convertView;
	}

	public final class ViewHolderHead {
		public TextView title;
	}

	public final class ViewHolderItem {
		public TextView content;
	}

}
